const Editor = require('../../src/index');
const expect = require('chai').expect;
const dom = document.createElement('div');
document.body.appendChild(dom);

describe('save index', () => {
  const page = new Editor.Flow({
    graph: {
      container: dom,
      height: 500
    },
    noEndEdge: false
  });
  const data = {
    nodes: [
      {
        label: '模型节点',
        shape: 'normal',
        x: 204,
        y: 188,
        id: 'a476209d',
        index: 0
      },
      {
        label: '开始节点',
        size: [
          60,
          60
        ],
        shape: 'start',
        x: 114,
        y: 79,
        id: '4988e9a7',
        index: 1
      },
      {
        label: '结束节点',
        size: [
          60,
          60
        ],
        shape: 'end',
        x: 226,
        y: 302,
        id: '11b6a5c7',
        index: 2
      },
      {
        label: '节点1',
        shape: 'start',
        x: 368,
        y: 240.5,
        id: '07c80b73',
        parent: 'ea4ca56f',
        index: 6
      },
      {
        label: '节点2',
        shape: 'start',
        x: 468,
        y: 240.5,
        id: '1b3aca28',
        parent: 'ea4ca56f',
        index: 7
      }
    ],
    edges: [
      {
        source: '4988e9a7',
        sourceAnchor: 0,
        target: 'a476209d',
        targetAnchor: 0,
        id: 'd0e03c7a',
        index: 3
      },
      {
        source: 'a476209d',
        sourceAnchor: 1,
        target: '11b6a5c7',
        targetAnchor: 0,
        id: 'a78b51b4',
        index: 4
      }
    ],
    groups: [
      {
        label: '测试分组',
        data: {
          name: 'dk'
        },
        id: 'ea4ca56f',
        index: 5
      }
    ]
  };
  page.read(data);
  it('graph index equal to model index', () => {
    const graph = page.getGraph();
    const items = graph.getItems();
    const itemGroup = graph.get('_itemGroup');
    const children = itemGroup.get('children');
    items.forEach(item => {
      const model = item.getModel();
      const group = item.getGraphicGroup();
      const graphciIndex = children.indexOf(group);
      expect(model.index).equal(graphciIndex);
    });
  });
  it('destroy', () => {
    page.destroy();
  });
});

